#ifndef SVGLINEELEMENT_H
#define SVGLINEELEMENT_H

#include "../svgnodeelement.h"
#include "../pointitemcontainerdelegate.h"
#include "../ilink.h"

class PointItemContainer;

class ENTITYSHARED_EXPORT SvgLineElement : public SvgNodeElement, public PointItemContainerDelegate, public ILink
{
    Q_OBJECT
public:
    SvgLineElement(SvgNode *parent = 0);

    virtual void paint(QPainter *painter,
                       const QStyleOptionGraphicsItem *option,
                       QWidget *widget=0);
    virtual void onResize(QRectF rect);
    virtual SvgTypeENUM svgType() const {
		return SVG_LINE;
	}
    ///////add by sam 20140806
    void appendPoint(const QPointF &p);

    void setMouseMovePos(QPointF pos);

    void setDrawLineShow(bool vis);

    void updatePointItem();

    const QList<QPointF> &points() const{
        return m_points;
    }
    void setPoint(QPointF p, int idx){
        m_points.replace(idx, p);
        updateFrame();
        updateShape();
    }

    virtual void replaceWithScenePoint(bool isStart, QPointF newPoint);

    virtual QUuid getId() const{
        return m_id;
    }


    virtual QList<QPointF> actualScenePoints() const{
        QList<QPointF> list;
        foreach (const QPointF& p , m_points)
        {
            list.append(this->mapToScene(p));
        }
        return list;
    }

    virtual void onPointPosChanged(int idx, QPointF newPoint);

    virtual bool tiePointCheckDelegate(QPointF curr, QPointF *res) ;

    virtual bool twoEndpointsLinked();
protected:
	virtual QList<QPointF> alignPoints(QPointF &center);
	virtual void cloneImpl(SvgNode *node);
	virtual SvgNode* createThis(){ return new SvgLineElement; }
	virtual void fromXmlImpl(const QDomElement &xml);
	virtual QDomElement toXmlImpl(QDomElement &parent) const;
	virtual void updateFrame();
	virtual void updateShape();
private:
    QPointF m_p1;
    QPointF m_p2;
    QList<QPointF> m_points;
    PointItemContainer *m_pointItemContainer;
};



#endif // SVGLINEELEMENT_H
